package com.liuyk.commonlib.widget.contain;

import android.view.ViewGroup;

import com.liuyk.commonlib.widget.navigation.BaseAdapter;

import java.util.List;

/**
 * tab bar
 * <p>
 * Created by liuyakui on 2020/5/3.
 */
public class NavigationTabAdapter extends BaseAdapter<TablebarData, BottomNavigationItem> {

    @Override
    public BottomNavigationItem builderItemView(ViewGroup parent, int index) {
        return new BottomNavigationItem(parent.getContext());
    }

    @Override
    public void bindItemView(BottomNavigationItem itemView, int index) {
        itemView.renderItemView(index, getItem(index));
    }

    @Override
    public void clickItem(int index) {
        if (getItems() == null) {
            return;
        }
        reset();
        getItem(index).isSelect = true;
        for (int i = 0; i < getViews().size(); i++) {
            BottomNavigationItem itemView = getItemView(i);
            bindItemView(itemView, i);
        }
    }

    private void reset() {
        List<TablebarData> items = getItems();
        if (items == null || items.isEmpty()) {
            return;
        }
        for (TablebarData tablebarData : items) {
            tablebarData.isSelect = false;
        }
    }
}
